var spawn = require('child_process').spawn;
require('http').createServer(function(req, res){

    var exec = require('child_process').exec;
    exec('dir', function(err, stdout, stderr){
        if (err) {
            console.log('child process exited with error code ' + err.code);
            return;
        }
        console.log(stdout);
		res.write(new Buffer(stdout, 'utf8'));
		res.end();
    });
	
//    var child = spawn('dir');
//    child.stdout.on('data', function(data){
//        console.log('stdout: ' + data);
//    });
//    child.stdout.pipe(res);
    res.on('end', function(){
        child.kill();
    });
}).listen(4000);
